public class QuickSort {
    public static void main(String[] args) {
        int[] arr = {2,3,1};
        quick(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
    private static void quick(int[] arr,int start,int end) {
        if(start >= end) {
            return;
        }
        int left = start;
        int right = end;
        int tmp = arr[start];
        while (left < right) {
            while (arr[right] >= tmp && left < right){
                right--;
            }
            while (arr[left] <= tmp && left < right) {
                left++;
            }
            if(left < right) {
                int t = arr[left];
                arr[left] = arr[right];
                arr[right] = t;
            }
        }
        //相遇后将基准切换
        arr[start] = arr[left];
        arr[left] = tmp;
        //左边递归
        quick(arr,start,left-1);
        //右边递归
        quick(arr,right+1,end);
    }
}
